// components/table/table.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    fields: { // 表头
      type: Array,
      value: []
  },
  hasFixed: { // 表头
    type: Boolean,
    value: false
  },
  hasFixedTwo: {
    type: Boolean,
    value: false
  },
  list: { // 数据列表
    type: Array,
    value: []
    },
  hasOperation:{
    type: Boolean,
    value: false
  }, 
  },
  options: {
    addGlobalClass: true
  },
  /**
   * 组件的初始数据
   */
  data: {
    upActive: false,
    downActive: false,
    currentIndex:null
  },
  created: function () {
    console.log(this.data.fields, this.data.list)
  },

  /**
   * 组件的方法列表
   */
  methods: {
    upClick (e) {
      this.triggerEvent('upClick', { row: e.currentTarget.dataset.item });
      const index = e.currentTarget.dataset.index
      
      if (this.data.downActive) {
        this.data.downActive = false
      }
      if(index === this.data.currentIndex){
        this.data.upActive = !this.data.upActive
      }else{
        this.data.upActive = true
      }
      this.setData({
        currentIndex:index
      })
      this.setData({
        downActive: this.data.downActive,
        upActive: this.data.upActive
      })
    },
    downClick (e) {
      this.triggerEvent('downClick', { row: e.currentTarget.dataset.item });
      const index = e.currentTarget.dataset.index
      if (this.data.upActive) {
        this.data.upActive = false
      }
      if(index === this.data.currentIndex){
        this.data.downActive = !this.data.downActive
      }else{
        this.data.downActive = true
      }
      // this.data.downActive = !this.data.downActive
      
      this.setData({
        currentIndex:index
      })
      this.setData({
        upActive: this.data.upActive,
        downActive: this.data.downActive
      })
    },
    handler (e) {
      console.log(e)
      if (e.currentTarget.dataset.item.prop !== 'handler') return
      this.triggerEvent('handler', { row: e.currentTarget.dataset.row }, {})
    },
    detailHandle (e) {
      this.triggerEvent('detailHandler', { row: e.currentTarget.dataset.row }, {})
    }
  }
})
